import com.tianxiabuyi.Message;
import com.tianxiabuyi.utils.WechatQyPushTool;
import com.tianxiabuyi.weixin.common.media.MediaType;
import com.tianxiabuyi.weixin.common.media.MpArticle;
import com.tianxiabuyi.weixin.common.media.Video;
import com.tianxiabuyi.weixin.common.message.Article;
import com.tianxiabuyi.weixin.common.message.Media;
import com.tianxiabuyi.weixin.common.message.MpNews;
import com.tianxiabuyi.weixin.common.message.Text;
import com.tianxiabuyi.weixin.qy.message.json.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 企业号消息推送的demo示例，但有的参数未赋值，实际开发时根据需要赋值
 * Created by yanghaixiao on 2017/6/16.
 */
public class WechatQyMessagePushDemo {

    /**
     *   文本消息推送示例
     */
    public void sendText() {
        TextMessage textMessage = new TextMessage();
        Text text = new Text("asd");
        textMessage.setText(text);
        textMessage.setAgentId(18);
        textMessage.setToUser("yanghx");
        System.out.println(WechatQyPushTool.push(999, textMessage));
    }

    /**
     *  news消息
     */
    public void sendNews() {
        NewsMessage jsonMessage = new NewsMessage();
        com.tianxiabuyi.weixin.common.message.News news = new com.tianxiabuyi.weixin.common.message.News();
        Article article = new Article();
        article.setTitle("hello");
        article.setDescription("nihao");
        List<Article> list = new ArrayList<>();
        list.add(article);
        news.setArticles(list);
        jsonMessage.setNews(news);
        jsonMessage.setAgentId(18);
        jsonMessage.setToUser("yanghx");
        System.out.println(WechatQyPushTool.push(999, jsonMessage));
    }

    /**
     * 文件消息类型（图片）
     */
    public void sendFile() {
        FileMessage fileMessage = new FileMessage();
        Message msg =  WechatQyPushTool.uploadMateria(999, MediaType.image, "/Users/yanghaixiao/Desktop/3x.png");
        if (msg.getErrcode() != 0)
            return;
        Media media = new Media(msg.get("mediaid"));
        fileMessage.setMedia(media);
        fileMessage.setAgentId(18);
        fileMessage.setToUser("yanghx");
        System.out.println( WechatQyPushTool.push(999, fileMessage));
    }

    /**
     *  图片消息
     */
    public void sendImage() {

        ImageMessage imageMessage = new ImageMessage();
        Message msg =  WechatQyPushTool.uploadMateria(999, MediaType.image, "/Users/yanghaixiao/Desktop/3x.png");
        if (msg.getErrcode() != 0)
            return;
        Media media = new Media(msg.get("mediaid"));
        imageMessage.setMedia(media);
        imageMessage.setAgentId(18);
        imageMessage.setToUser("yanghx");
        System.out.println( WechatQyPushTool.push(999, imageMessage));
    }

    /**
     * video消息
     */
    public  void sendVideo() {
        VideoMessage videoMessage = new VideoMessage();
        Message msg =  WechatQyPushTool.uploadMateria(999, MediaType.video, "/Users/yanghaixiao/Desktop/IMG_1220.mp4");
        if (msg.getErrcode() != 0)
            return;
        Video video = new Video();
        video.setTitle("biaoti");
        video.setDesc("miaoshu");
        video.setMediaId(msg.get("mediaid"));
        videoMessage.setVideo(video);
        videoMessage.setAgentId(18);
        videoMessage.setToUser("yanghx");
        System.out.println( WechatQyPushTool.push(999, videoMessage));
    }

    /**
     * mpNews
     */
    public void sendMpNews() {
        MpNewsMessage mpNewsMessage = new MpNewsMessage();
        Message msg =  WechatQyPushTool.uploadMateria(999, MediaType.image, "/Users/yanghaixiao/Desktop/3x.png");
        if (msg.getErrcode() != 0)
            return;
        MpNews mpNews = new MpNews();
        MpArticle mpArticle = new MpArticle();
        mpArticle.setAuthor("asd");
        mpArticle.setContent("content");
        mpArticle.setTitle("title");
        mpArticle.setDigest("zhaiyao");
        mpArticle.setThumbMediaId(msg.get("mediaid"));
        mpNews.add(mpArticle);
        mpNews.add(mpArticle);
        mpNews.add(mpArticle);
        mpNewsMessage.setMpNews(mpNews);
        mpNewsMessage.setAgentId(18);
        mpNewsMessage.setToUser("yanghx");
        System.out.println( WechatQyPushTool.push(999, mpNewsMessage));
    }
    public static void main(String[] args) {


    }
}
